package com.maokeyang.messageboard.service.impl;

import com.maokeyang.messageboard.mapper.UserMapper;
import com.maokeyang.messageboard.model.User;
import com.maokeyang.messageboard.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 根据id查询用户信息
     *
     * @param id
     * @return
     */
    public User findById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    /**
     * 用户登录
     * @param mobile
     * @param password
     * @return
     */
    @Override
    public User login(String mobile, String password) {
        User user = new User();
        user.setMobile(mobile);
        user.setPassword(password);
        User useRes = userMapper.selectOne(user);

        return useRes;
    }

    /**
     * 用户注册
     *
     * @param user
     * @return
     */
    @Override
    public int register(User user) {
        user.setCreatedAt(new Date());
        user.setUpdatedAt(new Date());
        return userMapper.insertSelective(user);
    }
}
